package com.yanqu.road.server.cmd.activity.busyfarming;


import com.yanqu.road.pb.activity.BusyFarmingProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.busyfarming.BusyFarmingModule;
import com.yanqu.road.server.manger.activity.busyfarming.BusyFarmingMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_BUSY_FARMING_FRIEND_GET_REWARD,desc = "亲友酬谢-领取")
public class BusyFarmingGetFriendRewardCmd extends AbstractCommand {

    long dbId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BusyFarmingProto.BusyFarmingGetFriendRewardReqMsg reqMsg = BusyFarmingProto.BusyFarmingGetFriendRewardReqMsg.parseFrom(packet.getBytes());
        dbId = reqMsg.getDbId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(BusyFarmingMgr.getShowTimeActivityId() == 0){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if(!BusyFarmingMgr.activityInTime()){
            ret = GameErrorCode.E_BUSY_FARMING_ACTIVITY_NO_IN_TIME;
            return;
        }

        ret = player.getModule(BusyFarmingModule.class).getReward(dbId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            BusyFarmingProto.BusyFarmingGetFriendRewardRespMsg.Builder respMsg = BusyFarmingProto.BusyFarmingGetFriendRewardRespMsg.newBuilder();
            respMsg.setDbId(dbId);
            respMsg.setRet(ret);
            respMsg.setReward("");
            player.sendPacket(Protocol.U_BUSY_FARMING_FRIEND_GET_REWARD, respMsg);
        }
    }
}
